﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.ServiceModel;
using Amazon_Book_Search.AmazonService;
using Amazon.ECS.Addons;

namespace Amazon_Book_Search.Models
{
    public class AmazonDAO
    {
        // your Amazon ID's
        private const string accessKeyId = "AKIAJGANGMS6QFBSOEZQ";
        private const string secretKey = "JEJSJ2BkJ63JnkvPmtq8oiNLlMm2MBej/1/LM0XD";

        public static ItemSearchResponse searchItems(ItemSearchRequest request) 
        {
            // create a WCF Amazon ECS client
			BasicHttpBinding binding		= new BasicHttpBinding(BasicHttpSecurityMode.Transport);
			binding.MaxReceivedMessageSize	= int.MaxValue;
			AWSECommerceServicePortTypeClient client = new AWSECommerceServicePortTypeClient(binding,
				    new EndpointAddress("https://webservices.amazon.com/onca/soap?Service=AWSECommerceService"));

			// add authentication to the ECS client
			client.ChannelFactory.Endpoint.Behaviors.Add(new AmazonSigningEndpointBehavior(accessKeyId, secretKey));

			ItemSearch itemSearch		= new ItemSearch();
			itemSearch.Request			= new ItemSearchRequest[] { request };
			itemSearch.AWSAccessKeyId	= accessKeyId;
            itemSearch.AssociateTag     = "";

			// issue the ItemSearch request
			return client.ItemSearch(itemSearch);
        }

    }
}